

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.Video;
import com.loong.loong.hik.service.VideoService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 视频监控
 *
 * @author jinyiang
 * @date 2023-03-29 14:16:14
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/video" )
@Api(value = "video", tags = "视频监控管理")
public class VideoController {

    private final  VideoService videoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param video 视频监控
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_video_view')" )
    public R getVideoPage(Page page, Video video) {

    	return R.ok(videoService.page(page,
				Wrappers.query(video).lambda()
		.like(StringUtils.isNotEmpty(video.getVideoName()),Video::getVideoName,video.getVideoName())

		));
    }


    /**
     * 通过id查询视频监控
     * @param videoId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{videoId}" )
    @PreAuthorize("@pms.hasPermission('hik_video_view')" )
    public R getById(@PathVariable("videoId" ) Integer videoId) {
        return R.ok(videoService.getById(videoId));
    }

    /**
     * 新增视频监控
     * @param video 视频监控
     * @return R
     */
    @ApiOperation(value = "新增视频监控", notes = "新增视频监控")
    @SysLog("新增视频监控" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_video_add')" )
    public R save(@RequestBody Video video) {
        return R.ok(videoService.save(video));
    }

    /**
     * 修改视频监控
     * @param video 视频监控
     * @return R
     */
    @ApiOperation(value = "修改视频监控", notes = "修改视频监控")
    @SysLog("修改视频监控" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_video_edit')" )
    public R updateById(@RequestBody Video video) {
        return R.ok(videoService.updateById(video));
    }

    /**
     * 通过id删除视频监控
     * @param videoId id
     * @return R
     */
    @ApiOperation(value = "通过id删除视频监控", notes = "通过id删除视频监控")
    @SysLog("通过id删除视频监控" )
    @DeleteMapping("/{videoId}" )
    @PreAuthorize("@pms.hasPermission('hik_video_del')" )
    public R removeById(@PathVariable Integer videoId) {
        return R.ok(videoService.removeById(videoId));
    }


    /**
     * 导出excel 表格
     * @param video 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_video_export')" )
    public List<Video> export(Video video) {
        return videoService.list(Wrappers.query(video));
    }
}
